//
//  UserInfoTool.m
//  DDViedo
//
//  Created by iwind on 15/3/25.
//  Copyright (c) 2015年 赵 冰冰. All rights reserved.
//

#import "UserInfoTool.h"
#import "NSUserDefaults+TTUserDefaults.h"

/**
 用户权限信息 Key
 */
static NSString * const USER_PERMISSION_INFO = @"actorFunc";


@implementation UserInfoTool

#pragma mark - App Version
+ (NSString *)currentAppVersion {
    return [NSUserDefaults stringValueForKey:@"Current_App_Version"];
}

+ (void)saveCurrentAppVersion:(NSString *)appVersion {
    [NSUserDefaults setValue:appVersion forKey:@"Current_App_Version"];
}
#pragma mark - First Launch
+ (BOOL)firstLaunch {
    return [NSUserDefaults boolValueForKey:@"First Launch"];
}

+ (void)saveFirstLaunchState:(BOOL)state {
    [NSUserDefaults setBoolValue:state forKey:@"First Launch"];
}


#pragma mark - First in Home View
+ (BOOL)firstInHomeView {
    return [NSUserDefaults boolValueForKey:@"First in Home View"];
}

+ (void)saveFirstInHomeState:(BOOL)state {
    [NSUserDefaults setBoolValue:state forKey:@"First in Home View"];
}



#pragma mark - Data Version
+ (NSString *)getDataVersion {
    return [NSUserDefaults stringValueForKey:@"version"];
}

+ (void)saveDataVersion:(NSString *)version {
    [NSUserDefaults setValue:version forKey:@"version"];
}


#pragma mark - User Canuseca
+ (NSString*)getUserCanuseca {
    return [NSUserDefaults stringValueForKey:@"canuseca"];
}

+ (void)saveUserCanuseca:(NSString*)userCanuseca {
    [NSUserDefaults setValue:userCanuseca forKey:@"canuseca"];
}

#pragma mark - User acclevel
+ (NSString*)getUserAcclevel {
    return [NSUserDefaults stringValueForKey:@"acclevel"];
}

+ (void)saveUserAcclevel:(NSString*)userAcclevel {
    [NSUserDefaults setValue:userAcclevel forKey:@"acclevel"];
}


#pragma mark - User ID
+ (NSString *)getUserId {
    return [NSUserDefaults stringValueForKey:@"userId"];
}

+ (void)saveUserId:(NSString*)userId {
    [NSUserDefaults setValue:userId forKey:@"userId"];
}


#pragma mark - Token
+ (NSString *)getToken {
  return [NSUserDefaults stringValueForKey:@"token"];
}

+ (void)saveToken:(NSString*)token {
    [NSUserDefaults setValue:token forKey:@"token"];
}

+ (void)deleteToken {
    [NSUserDefaults removeObjectForKey:@"token"];
}


#pragma mark - User Name
+ (NSString *)getUserName {
    return [NSUserDefaults stringValueForKey:UserName];
}

+ (void)saveCurrentUserName:(NSString *)userName {
    [NSUserDefaults setValue:userName forKey:UserName];
}


#pragma mark - User Code
+ (NSString *)getUserCode {
    return [NSUserDefaults stringValueForKey:UserCode];
}

+ (void)saveCurrentUserCode:(NSString *)userCode {
    [NSUserDefaults setValue:userCode forKey:UserCode];
}


#pragma mark - User Role
+ (NSArray<NSString *> *)getUserRoles {
    return [NSUserDefaults arrayValueForKey:UserRols];
}

+ (void)saveUserRoles:(NSArray<NSString *> *)userRoles {
    [NSUserDefaults setObjectValue:userRoles forKey:UserRols];
}


#pragma mark - OrgName
+ (NSString *)getOrgName {
    return [NSUserDefaults stringValueForKey:OrgName];
}

+ (void)saveOrgName:(NSString *)orgName {
    [NSUserDefaults setObjectValue:orgName forKey:OrgName];
}


#pragma mark - Addition Info
+ (NSArray *)addition {
    return [NSUserDefaults arrayValueForKey:@"ADDITION"];
}

+ (void)saveAddition:(NSArray *)addition {
    [NSUserDefaults setObjectValue:addition forKey:@"ADDITION"];
}


#pragma mark - User Permission Info
// 用户权限信息
+ (NSDictionary *)userPermissionInfo {
    return [NSUserDefaults dictionaryValueForKey:USER_PERMISSION_INFO];
}

// 保存用户权限信息
+ (void)saveUserPermissionInfo:(NSDictionary *)info {
    [NSUserDefaults setObjectValue:info forKey:USER_PERMISSION_INFO];
}


#pragma mark - New Car Permission
// 本品新车权限
+ (BOOL)newCarPermission {
    return [NSUserDefaults boolValueForKey:@"enable_new"];
}

// 保存本品新车权限
+ (void)saveNewCarPermission:(BOOL)permission {
    [NSUserDefaults setBoolValue:permission forKey:@"enable_new"];
}


#pragma mark - Second Hand Permission
// 二手车权限
+ (BOOL)secondHandPermission {
    return [NSUserDefaults boolValueForKey:@"enable_old"];
}

// 保存二手车权限
+ (void)saveSecondHandPermission:(BOOL)permission {
    [NSUserDefaults setBoolValue:permission forKey:@"enable_old"];
}


#pragma mark - Org Loan Permission
// 机构权限
+ (BOOL)orgLoanPermission {
    return [NSUserDefaults boolValueForKey:@"enable_org"];
}

// 保存机构权限
+ (void)saveOrgLoanPermission:(BOOL)permission {
    [NSUserDefaults setBoolValue:permission forKey:@"enable_org"];
}


#pragma mark - All Brand Permission
// 全品牌权限
+ (BOOL)allBrandPermission {
    return [NSUserDefaults boolValueForKey:@"enableSp"];
}

// 保存全品牌权限
+ (void)saveAllBrandPermission:(BOOL)permission {
    [NSUserDefaults setBoolValue:permission forKey:@"enableSp"];
}


#pragma mark -
+ (CGFloat)getDintanceBylatitude:(CLLocationDegrees)latitude
                       Longitude:(CLLocationDegrees)longitude
{
    CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude] ;
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *savedLatitude = [userDefaults objectForKey:@"latitude"];
    NSString *savedLongitude = [userDefaults objectForKey:@"longitude"];
    CLLocation *savedLocation = [[CLLocation alloc] initWithLatitude:[savedLatitude doubleValue] longitude:[savedLongitude doubleValue]] ;

    CLLocationDistance kilometers = [currentLocation distanceFromLocation:savedLocation];

    return kilometers;
}


#pragma mark - Device ID
+ (NSString *)getDeviceId {
    NSUUID * currentDeviceUUID  = [UIDevice currentDevice].identifierForVendor;
    NSString * currentDeviceUUIDStr = currentDeviceUUID.UUIDString;
    currentDeviceUUIDStr = [currentDeviceUUIDStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
    currentDeviceUUIDStr = [currentDeviceUUIDStr lowercaseString];
    return currentDeviceUUIDStr;
}


#if DEBUG
// 服务器环境
+ (NSInteger)serverType {
    return [NSUserDefaults integerValueForKey:@"SERVER_TYPE"];
}

// 保存服务器环境
+ (void)saveSerserType:(NSInteger)type {
    [NSUserDefaults setIntegerValue:type forKey:@"SERVER_TYPE"];
}
#endif

@end
